﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title></title>
        <link type="text/css" rel="stylesheet" media="all" href="../styles/global.css" />
        <link type="text/css" rel="stylesheet" media="all" href="../styles/global_color.css" />
        <script src="../js/jquery-3.2.1.js"></script>
        <script language="javascript" type="text/javascript">
            $.ajax({
                url: "/selectAllModules",
                type: "post",
                success: function (result) {
                    console.log(result)

                    if (result.indexOf("角色管理") == -1) {
                        document.getElementById("lia1").style.display = "none"
                    }
                    if (result.indexOf("管理员管理") == -1) {
                        document.getElementById("lia2").style.display = "none"
                    }
                    if (result.indexOf("资费管理") == -1) {
                        document.getElementById("lia3").style.display = "none"
                    }
                    if (result.indexOf("账务账号管理") == -1) {
                        document.getElementById("lia4").style.display = "none"
                    }
                    if (result.indexOf("业务账号管理") ==-1) {
                        document.getElementById("lia5").style.display = "none"
                    }
                    if (result.indexOf("账单管理") ==-1) {
                        document.getElementById("lia6").style.display = "none"
                    }
                    if (result.indexOf("报表管理") == -1) {
                        document.getElementById("lia7").style.display = "none"
                    }
                }
            });




            var accountId = "";


            $.ajax({
                url:"allopencost",
                type:"post",
                success:function (result) {
                    for (var i in result){
                        var cost = result[i];
                        $("#costname").append("<option value='"+cost.costId+"'>"+cost.name+"</option>")
                    }
                }
            })

            //查询accountId
            function searchByCardId() {
                $.ajax({
                    url:"selectaccountbycardid",
                    type:"post",
                    data:{
                        cardId:$("#cardId").val(),
                    },
                    success:function (result) {
                        console.log(result)
                        var account = result.data;
                        accountId = account.accountId;
                        if (result.message == "查询失败"){
                            alert("没有此身份证号，请重新录入。")
                        }else {
                            $("#accountname").val(account.loginName)
                        }
                    }
                })
            }


            //保存成功的提示信息
            function showResult() {
                $.ajax({
                    url: "addservice",
                    type: "post",
                    data: {
                        accountId:accountId,
                        unixHost:$("#ip").val(),
                        osusername:$("#osusername").val(),
                        password: $("#password").val(),
                        password1: $("#password1").val(),
                        costId: $("#costname").val()
                    },
                    success:function (result) {
                        alert(result.message)
                        window.location.href = "/servicelist";
                    }
                })
            }

            function showResultDiv(flag) {
                var divResult = document.getElementById("save_result_info");
                if (flag)
                    divResult.style.display = "block";
                else
                    divResult.style.display = "none";
            }

            //自动查询账务账号
            function searchAccounts() {
                $.ajax({
                    url:"selectaccountbyaccountname",
                    type:"post",
                    data:{
                        accountname:$("#accountname").val(),
                    },
                    success:function (result) {
                        var account = result.data;
                        if (account == null){
                            $(".validate_msg_long").val("没有此账号，请重新录入。")
                        }
                    }

                })
            }
        </script>
    </head>
    <body>
        <!--Logo区域开始-->
        <div id="header">
            <img src="../images/logo.png" alt="logo" class="left"/>
            <a href="/logout">[退出]</a>
        </div>
        <!--Logo区域结束-->
        <!--导航区域开始-->
        <div id="navi">
            <ul id="menu">
                <li><a href="../index.html" class="index_off"></a></li>
                <li id="lia1"><a href="rolelist" class="role_off"></a></li>
                <li id="lia2"><a href="adminlist" class="admin_off"></a></li>
                <li id="lia3"><a href="fee" class="fee_off"></a></li>
                <li id="lia4"><a href="accountlist" class="account_off"></a></li>
                <li id="lia5"><a href="servicelist" class="service_on"></a></li>
                <li id="lia6"><a href="bill" class="bill_off"></a></li>
                <li id="lia7"><a href="report" class="report_off"></a></li>
                <li><a href="userinfo" class="information_off"></a></li>
                <li><a href="changepsw" class="password_off"></a></li>
            </ul>
        </div>
        <!--导航区域结束-->
        <!--主要区域开始-->
        <div id="main">
            <!--保存操作的提示信息-->
            <div id="save_result_info" class="save_fail">保存失败！192.168.0.23服务器上已经开通过 OS 账号 “mary”。</div>
            <form action="" method="" class="main_form">
                <!--内容项-->
                <div class="text_info clearfix"><span>身份证：</span></div>
                <div class="input_info">
                    <input type="text" value="" class="width180" id="cardId" />
                    <input type="button" value="查询账务账号" onclick="searchByCardId()" class="btn_search_large" />
                    <span class="required" id="desc">*</span>
                    <div class="validate_msg_short"></div>
                </div>
                <div class="text_info clearfix"><span>账务账号：</span></div>
                <div class="input_info">
                    <input type="text" value="" onkeyup="searchAccounts();" id="accountname" />
                    <span class="required">*</span>
                    <div class="validate_msg_long"></div>
                </div>
                <div class="text_info clearfix"><span>资费类型：</span></div>
                <div class="input_info">
                    <select id="costname">

                    </select>                        
                </div> 
                <div class="text_info clearfix"><span>服务器 IP：</span></div>
                <div class="input_info">
                    <input type="text" value="" id="ip" />
                    <span class="required">*</span>
                    <div class="validate_msg_long">15 长度，符合IP的地址规范</div>
                </div>                   
                <div class="text_info clearfix"><span>登录 OS 账号：</span></div>
                <div class="input_info">
                    <input type="text" value="" id="osusername" placeholder="创建即启用，状态为开通" />
                    <span class="required">*</span>
                    <div class="validate_msg_long">8长度以内的字母、数字和下划线的组合</div>
                </div>
                <div class="text_info clearfix"><span>密码：</span></div>
                <div class="input_info">
                    <input type="password" id="password" />
                    <span class="required">*</span>
                    <div class="validate_msg_long">30长度以内的字母、数字和下划线的组合</div>
                </div>
                <div class="text_info clearfix"><span>重复密码：</span></div>
                <div class="input_info">
                    <input type="password" id="password1" />
                    <span class="required">*</span>
                    <div class="validate_msg_long">两次密码必须相同</div>
                </div>     
                <!--操作按钮-->
                <div class="button_info clearfix">
                    <input type="button" value="保存" class="btn_save" onclick="showResult();" />
                    <input type="button" value="取消" class="btn_save" onclick="location.href='servicelist'" />
                </div>
            </form>
        </div>
        <!--主要区域结束-->
        <div id="footer">
            <span>[源自北美的技术，最优秀的师资，最真实的企业环境，最适用的实战项目]</span>
            <br />
            <span>版权所有(C)云科技有限公司 </span>
        </div>
    </body>
</html>
